<!--Generate by Kevin's CodeBuilder -->
<!--请注意！这里是页面片段，定义的标签ID，js变量不要与index.html列表页面重复-->
<!--如果是较复杂的页面，可以修改window的数据类型(dataType: iframe),然后将form.html改为完整的页面,实现iframe隔离，需要修改curdObj的访问方式为parent.curdObj-->
<div id="form_container" class="form_container">
		<!--利用隐藏的id标签区分是新增/编辑-->
		<input type="hidden" id="id" name="id" th:value="*{id}"/>
		<input type="hidden" id="old_roleName" name="old_roleName" value=""/>
		<table class="form_table" style="margin-top:30px">				
				<tr>
					<td class="label label30">[(${Lang.role_roleName})]</td>
					<td><input id="roleName" name="roleName" class="form_input form_input50" type="text"/></td>
				</tr>
				<tr>
					<td class="label label30">[(${Lang.role_roleStatus})]</td>
					<td>					
						<label class="k_radio_label k_radio_anim">
                            <input type="radio" name="roleStatus" checked="checked" value="1" /><i class="k_radio_i"></i>[(${Lang.common_yes})]
                        </label>
                        <label class="k_radio_label k_radio_anim">
                            <input type="radio" name="roleStatus" value="0" /><i class="k_radio_i"></i>[(${Lang.common_no})]
                        </label>					
					</td>
				</tr>
				<tr>
					<td class="label label30">[(${Lang.role_defaultRole})]</td>
					<td>					
						<label class="k_radio_label k_radio_anim">
                            <input type="radio" name="defaultRole"  value="1" /><i class="k_radio_i"></i>[(${Lang.common_yes})]
                        </label>
                        <label class="k_radio_label k_radio_anim">
                            <input type="radio" name="defaultRole" checked="checked" value="0" /><i class="k_radio_i"></i>[(${Lang.common_no})]
                        </label>
                      </td>
				</tr>
				<tr>
					<td class="button_td" colspan="2">
						<button id="button_submit" class="common_button"><i class="fa fa-floppy"></i>[(${Lang.common_save})]</button>
						<button id="button_goback"  class="common_button"><i class="fa fa-reply-all"></i>[(${Lang.common_goback})]</button>
					</td>
				</tr>
		</table>
</div>
<script type="application/javascript" th:inline="javascript">
		var $form,
			entityJson,
			vm,
			idValue;//用于区分新增,编辑
		$(function(){
			$form = $("#form_container");
			idValue = $form.find("#id").val();
			/**创建mvvm表单，将实体json绑定到表单**/
			if(idValue === ""){
				entityJson = $B.parseForm($form);
			}else{
				entityJson = [(${entityJson})];
			}
			vm = $B.bindForm($form, entityJson);/***将实体数据绑定为mvvm表单***/
			/**绑定事件**/
			$form.find("#button_goback").click(function(){
				curdObj.closeWindow();
			});
			var validObj = new $B.Validate({
				roleName: [{rule:'require'}]
            }, $form);
			
			$form.find("#button_submit").submit(function(){
				//提交表单数据
				var isPast = validObj.valid();				
				if(isPast){
					if(idValue === ""){
						curdObj.add(vm.getJson());
					}else{
						curdObj.update(vm.getJson());
					}
				}
			});
		});
</script>
